const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    url: '',
    title:'登录',
    hasMobile: false //没有手机号
  },
  onLoad(option) {

  },
  bindgetuserinfoBtn(e) {
    app.GetLogin()
    app.tokenReadyCallback = res => {
      console.log('tokenReadyCallback', res)
      if (!Boolean(res.data.baseData.mobile)) {
        // 不存在手机号
        this.setData({
          hasMobile: true
        })
      } else {
        wx.showToast({
          title: '登录成功！',
          icon: 'success',
          duration: 2000
        })
        app.updateScore(2)
        setTimeout(res => {
          wx.navigateBack({ //返回
            delta: 1
          })
        })
        wx.setStorageSync('telephone', res.data.baseData.mobile)
      }
    }
  },
  // 手机授权
  bindgetphonenumber(e) {
    console.log('手机授权', e)
    app.updatePhoneNumber(e.detail)
      .then(res => {
        
          wx.showToast({
            title: '登录成功！',
            icon: 'success',
            duration: 2000
          })
          app.updateScore(2)
          setTimeout(res => {
            wx.navigateBack({ //返回
              delta: 1
            })
          })
        
        wx.setStorageSync('telephone', res.data.baseData)
      })
  },
  onShareAppMessage: function (e) {
    // if (e.from == "button") {
      let obj = {
        title: '有氧FM·登录',
        success: function (res) {
          
        },
        fail(err) {
          
        }
      }
      return obj
    // }
  },
  onShareTimeline: function (e) {
    // if (e.from == "button") {
      let obj = {
        title: '有氧FM·登录',
        success: function (res) {
          
        },
        fail(err) {
          
        }
      }
      return obj
    // }
  },
})